$("#checkAll").click(function(){
		var allCheck = this;
		$(".check_mobile").each(function(){
			this.checked = allCheck.checked;
		});
	});
	
var mobile_content = window.parent.document.getElementById("mobiles");
var MOBILES_MAX_LENGTH = 200;

$("#select_mobiles_btn").click(function(){
	var mobiles = [];
	$(".check_mobile").each(function(){
		if (this.checked || this.checked == 'true') {
			mobiles.push($.trim($(this).attr("data-ref")));
		}
	});
	
	if (mobiles.length <= 0) {
		return;
	}
	
	if (mobiles.length > MOBILES_MAX_LENGTH) {
		alert("手机号码最多为200个目前为" + (mobiles.length) + "个！");
		return;
	}
	
	var old = $.trim(mobile_content.value);
	
	// 避免重复包含号码
	if (old) {
		var newMobiles = [];
		var oldMobiles = old.split(/\s+/);
		for (var i = 0; i < mobiles.length; i++) {
			var flag = true;
			var one = $.trim(mobiles[i]);
			for (var j = 0; j < oldMobiles.length; j++) {
				if (one == $.trim(oldMobiles[j])) {
					flag = false;
					break;
				}	
			}
			if (flag) {
				newMobiles.push(one);
			}
		}
		
		if ((oldMobiles.length + newMobiles.length) >  MOBILES_MAX_LENGTH) {
			alert("手机号码最多为200个目前为" + (oldMobiles.length + newMobiles.length) + "个！");
		} else {
			mobile_content.value = old + " " + newMobiles.join(" ");
		}
	} else {
		mobile_content.value = mobiles.join(" ");
	}
	
});